package mtt.model.calendar;

import java.util.Hashtable;



public class Day {
	/**
	 * Index "Freitag" für den Week.hashtableDays
	 */
	public static final int index_FRIDAY = 4;

	/**
	 * Index "Montag" für den Week.hashtableDays
	 */
	public static final int index_MONDAY = 0;

	/**
	 * Index "Samstag" für den Week.hashtableDays
	 */
	public static final int index_SATURDAY = 5;

	/**
	 * Index "Sonntag" für den Week.hashtableDays
	 */
	public static final int index_SUNDAY = 6;

	/**
	 * Index "Donnerstag" für den Week.hashtableDays
	 */
	public static final int index_THURSDAY = 3;

	/**
	 * Index "Dienstag" für den Week.hashtableDays
	 */
	public static final int index_TUESDAY = 1;

	/**
	 * Index "Mittwoch" für den Week.hashtableDays
	 */
	public static final int index_WEDNESDAY = 2;
	
	/**
	 * enthält alle Events des Tages
	 * 
	 */
	private Hashtable hashtableEvents = new Hashtable(7);
	
	/**
	 * definiert um welchen tag es sich handelt, enthält einen der Day.index_* konstanten
	 */
	private int indexOfDay;
	
	/**
	 * fügt ein Event der Event-Liste hinzu, 
	 * @param event
	 * @throws NullPointerException if indexOfEvent is not set
	 * @throws IndexOutOfBoundsException if the index is not between Event.index_TIME_07To09 and Event.index_TIME_19To21
	 */
	public void addEvent(Event event) throws NullPointerException, IndexOutOfBoundsException {
		if (this.hashtableEvents == null) {
			this.hashtableEvents = new Hashtable();
		}
		
		this.hashtableEvents.put(event.getTimeIndexOfEvent(), event);
	}
	
	/**
	 * liefert das Event mit dem angegebenen Index
	 * @return Event oder null falls es kein Event mit dem index gibt
	 */
	public Event getEventOfDay(int indexTimeOfEvent) throws IndexOutOfBoundsException {
		
		if ((indexTimeOfEvent < Event.index_TIME_07To09) || (indexTimeOfEvent > Event.index_TIME_19To21)) {
			throw new IndexOutOfBoundsException("Der index muss zwischen Event.index_TIME_07To09 und Event.index_TIME_19To21 liegen");
		}
		
		if (hashtableEvents.contains(new Integer(indexTimeOfEvent))) {
			return (Event) this.hashtableEvents.get(new Integer(indexTimeOfEvent));
		} else {
			Event event = new Event();
			event.setTimeIndexOfEvent(new Integer(indexTimeOfEvent));
			event.setDayOfEvent(indexOfDay);
			/*
			 * Event zur Liste hinzufügen
			 */
			hashtableEvents.put(new Integer(indexTimeOfEvent), event);
			
			return event;
		}
		
		
	}

	public Hashtable getHashtableEvents() {
		return hashtableEvents;
	}

	public int getIndexOfDay() {
		return indexOfDay;
	}

	public void setHashtableEvents(Hashtable hashtableEvents) {
		this.hashtableEvents = hashtableEvents;
	}
	
	/**
	 * setzt den index (Day.index_*) des Tages den das Date-Objekt
	 * repräsentieren soll
	 * 
	 * @param indexOfDay
	 * @throws IndexOutOfBoundsException
	 */
	public void setIndexOfDay(int indexOfDay) throws IndexOutOfBoundsException {

		if ((indexOfDay > index_SUNDAY) || (indexOfDay < index_MONDAY)) {
			throw new IndexOutOfBoundsException(
					"Der index muss zwischen Day.index_Monday und Day.index_SUNDAY liegen");
		}

		this.indexOfDay = indexOfDay;
	}
	
	/**
	 * liefert den Namen des Tages für die angegebene Week.ID_
	 * @param id
	 * @return den Namen des Tages oder null
	 */
	public static String getStringOfDayId (int id) {
		if (id == index_MONDAY) {
			return "Montag";
		} else if (id == index_TUESDAY) {
			return "Dienstag";
		} else if (id == index_WEDNESDAY) {
			return "Mittwoch";
		} else if (id == index_THURSDAY) {
			return "Donnerstag";
		} else if (id == index_FRIDAY) {
			return "Freitag";
		} else if (id == index_SATURDAY) {
			return "Samstag";
		} else if (id == index_SUNDAY) {
			return "Sonntag";
		} else {
			return null;
		}
	}
}
